// pages/home/home.js
import request from '../../utils/request'
Page({

  /**
   * 页面的初始数据
   */
  data: {
    dataList:['新闻资讯','通知公告','工作动态'],
    dataNews:[],
    activeIndex:0,
    banner: [],
    indicatorDots: true,
    vertical: false,
    autoplay: true,
    interval: 2000,
    duration: 500
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    let that = this;
    var data = {
      page:1,
      limit:3,
    }
    var consultData={
      type:1,
      search:'',
      page:1,
      limit:3
    }
    var vitaeData={
      search:'',
      page:1,
      limit:3
    }
    // 会员风采
    request.get('article/list/5',data,{ noAuth : true}).then(res=>{
      that.setData({
        member:res.data
      })
    }).catch(err=>{
      console.log(err)
    }),
     // 咨询服务
      request.get('consultation',consultData,{ noAuth : true}).then(res=>{
        console.log(data)
        if(res.status==200){
          console.log(res.data)
          that.setData({
            consultData:res.data
          })
        }
      }),
      // 人才中心
      request.get('vitae',vitaeData,{ noAuth : true}).then(res=>{
      
        if(res.status==200){
          var arrList = res.data
          for (var i=0; i<= 2;i++){
            arrList[i].birthday = this.getAge(arrList[i].birthday)
          }

      console.log(arrList)
          that.setData({
            resumeList:arrList
          })
        }
      })
    // 工作动态
    request.get('article/list/4',data,{ noAuth : true}).then(res=>{
      console.log(res)
      that.setData({
        workdata:res.data
      })
    }),
    //通知公告
    request.get('article/list/3',data,{ noAuth : true}).then(res=>{
      console.log(res)
      that.setData({
        notice:res.data
      })
    }),
    // 新闻咨询
    request.get('article/list/2',data,{ noAuth : true}).then(res=>{
      console.log(res)
      that.setData({
        news:res.data
      })
    }),
    // 培训服务
    request.get('article/list/6',data,{ noAuth : true}).then(res=>{
      that.setData({
        traindata:res.data
      })
    })
    that.getBanner()
    
  },
  goDetail:function(o){
    var id = o.currentTarget.dataset.id
    wx.navigateTo({
      url: '/pages/moreList/datadetails/datadetails?id='+id,
    })
  },
  GoitemInfo:function(i){
    var url = i.currentTarget.dataset.url
    console.log(url)
    wx.navigateTo({
      url: url,
    })
  },
  goPages:function(){
    wx.navigateTo({
      url: '../Summary/Summary',
    })
  },

  getBanner:function(){
    request.get('banner/index_banner',{},{ noAuth : true}).then(res=>{
      console.log(res)
      this.setData({
        banner:res.data
      })
    })
  },
  changeSwiper(e){
    console.log(e.detail.current)
    this.setData({
      activeIndex: e.detail.current
    })
  },
  getMore:function(){
   wx.navigateTo({
     url: '../moreList/moreList',
   })
  },
  newsdetails:function(){
    wx.navigateTo({
      url: '../moreList/datadetails/datadetails',
    })
  },
  getIndex:function(e){
    console.log(e)
    this.setData({
      activeIndex:e.detail.index
    })
  },
  businessDetails:function(c){
   var id = c.currentTarget.dataset.id
    wx.navigateTo({
      url: '../member/business_details/business_details?id='+id
    })
  },
  trainDetail:function(t){
    var id = t.currentTarget.dataset.id
    wx.navigateTo({
      url: '../train/case/case?id='+id
    })
  },
  goConsult:function(){
    wx.navigateTo({
      url: '../consult/consult'
    })
  },
  goTalent:function(){
    wx.navigateTo({
      url: '../talent/talent'
    })
  },
  goTrain:function(){
    wx.navigateTo({
      url: '../train/train'
    })
  },

  getAge(strBirthday) {
    console.log(strBirthday)
   var returnAge = '';
   var mouthAge = '';
   var strBirthdayArr = strBirthday.split("-");
   var birthYear = strBirthdayArr[0];
   var birthMonth = strBirthdayArr[1];
   var birthDay = strBirthdayArr[2];
   var d = new Date();
   var nowYear = d.getFullYear();
   var nowMonth = d.getMonth() + 1;
   var nowDay = d.getDate();
   if (nowYear == birthYear) {
     // returnAge = 0; //同年 则为0岁
     var monthDiff = nowMonth - birthMonth; //月之差 
     if (monthDiff < 0) {
     } else {
       mouthAge = monthDiff + '个月';
     }
   } else {
     var ageDiff = nowYear - birthYear; //年之差
     if (ageDiff > 0) {
       if (nowMonth == birthMonth) {
         var dayDiff = nowDay - birthDay; //日之差 
         if (dayDiff < 0) {
           returnAge = ageDiff - 1 + '岁';
         } else {
           returnAge = ageDiff + '岁';
         }
       } else {
         var monthDiff = nowMonth - birthMonth; //月之差 
         if (monthDiff < 0) {
           returnAge = ageDiff - 1 + '岁';
         } else {
           mouthAge = monthDiff + '个月';
           returnAge = ageDiff + '岁';
         }
       }
     } else {
       returnAge = -1; //返回-1 表示出生日期输入错误 晚于今天
     }
   }
   return returnAge + mouthAge; //返回周岁年龄+月份
 },
 talentDetail:function(e){
  var id = e.currentTarget.dataset.id
  wx.navigateTo({
    url: '../talent/resumeDetails/resumeDetails?id='+id,
  })
 },
  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  }
})